package com.example.lottery.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.lottery.entity.DbBettingData;
import com.example.lottery.mapper.dao.DbBettingDataDAO;
import com.example.lottery.res.BettingDataResponse;
import com.example.lottery.service.DbBettingDataService;
import com.example.lottery.util.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 投注数据 服务实现类
 * </p>
 *
 * @author tanwei
 * @since 2024-03-01
 */
@Service
public class DbBettingDataServiceImpl extends ServiceImpl<DbBettingDataDAO, DbBettingData> implements DbBettingDataService {

    @Autowired
    DbBettingDataDAO dbBettingDataDAO;

    @Override
    public List<DbBettingData> getBettingData() {
        List<DbBettingData> bettingData = dbBettingDataDAO.getBettingData();
        return bettingData;
    }

    @Override
    public void insertBettingData(List<BettingDataResponse> data) {
        List<DbBettingData> dbBettingData = ObjectUtils.buildBatch(DbBettingData.class, data);
        dbBettingData.forEach(m -> {
            m.setCreateId("system");
            m.setCreateDate(LocalDateTime.now());
        });
        this.saveBatch(dbBettingData);
    }

    @Override
    public void deleteData() {
        dbBettingDataDAO.clearData();
    }


}
